define(["jquery"],function($){
	$.fn.extend({
		pwx:function(obj){
			var btn = $("#" + obj.btn),
				gwc = $("." + obj.gwc);
			btn.click(function(){
				var p1 = {
							x: btn.offset().left,
							y: btn.offset().top
						};
				//终点
				var p2 = {
					x: gwc.offset().left,
					y: gwc.offset().top
				};
				//顶点
				//top的纵坐标不能超出屏幕
				var p3 = {
					x: p2.x - 200,
					y: p2.y - 50 > 0 ? p2.y - 50 : 0
				};
		
				var a = -((p2.y-p3.y)*p1.x-(p2.x-p3.x)*p1.y+p2.x*p3.y-p3.x*p2.y)/((p2.x-p3.x)*(p1.x-p2.x)*(p1.x-p3.x));
				var b = ((p2.y-p3.y)*p1.x*p1.x+p2.x*p2.x*p3.y-p3.x*p3.x*p2.y-(p2.x*p2.x-p3.x*p3.x)*p1.y)/((p2.x-p3.x)*(p1.x-p2.x)*(p1.x-p3.x));
				var c = ((p2.x*p3.y-p3.x*p2.y)*p1.x*p1.x-(p2.x*p2.x*p3.y-p3.x*p3.x*p2.y)*p1.x+(p2.x*p2.x*p3.x-p2.x*p3.x*p3.x)*p1.y)/((p2.x-p3.x)*(p1.x-p2.x)*(p1.x-p3.x));
				
				//创建元素让他进行抛物线运动
				var div =$("<div>");
				div.css({
                        "width":"20",
                        "height":"20",
                        "background":"skyblue",
                        "position":"absolute",
                        "left":p1.x,
                        "top": p1.y
                        }).appendTo("body");

				//初始位置就是按钮的位置
				/*div.style.left = p1.x + "px";
				div.style.top = p1.y + "px";*/
				var _left = p1.x;
				var _top;
				console.log(548)
				//横坐标水平右移，纵坐标按照抛物线计算
				var timer = setInterval(function(){
					_left+=40;
					alert(123)
					_top = a*_left*_left + b*_left + c;
					div.css({"left":_left,"top":_top})
					/*div.style.left = _left + "px";
					div.style.top = _top + "px";*/
					if(_left >= p2.x){
						alert(123)
						//加入购物车成功，到达终点
						clearInterval(timer);
						/*$("body").remove(div)*/
						div.remove();
					}
				},30);
			})
		}
	})
})